package it.duecaffe.claysoftware.interventi.client.view;

import it.duecaffe.claysoftware.interventi.client.images.ClayResources;
import it.duecaffe.claysoftware.interventi.shared.models.UtenteModel;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;

/**
 * Gescisce la sezione superiore dell'applicativo con visualizzazione
 * della barra del titolo
 * @author Alex
 *
 */
public class TitlePanel extends HorizontalPanel {
	
	private ClayResources IMAGES = GWT.create(ClayResources.class);
	
	/**
	 * Costruttore
	 * @param tecnico Dati del tecnico
	 */
	public TitlePanel(UtenteModel tecnico) {
		setBorderWidth(2);	
		setWidth("100%");
	    setHeight("100%");
		init(tecnico);
	}
	
	private void init(UtenteModel tecnico) {
		
		FlexTable flexTable = new FlexTable();
		FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
	    flexTable.addStyleName("cw-FlexTable");
	    flexTable.setWidth("100%");
	    flexTable.setCellSpacing(5);
	    flexTable.setCellPadding(3);
	    
		// Logo clay
	    Image image = new Image(IMAGES.logo());
	    cellFormatter.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
	    
	    flexTable.setWidget(0, 0, image);
	    flexTable.getCellFormatter().setWidth(0, 0, "80%");
	    
	    FlexTable flexUtente = new FlexTable();
	    FlexCellFormatter cellUtFormatter = flexUtente.getFlexCellFormatter();
	    Image imgTec = new Image(IMAGES.amm_48());
	    flexUtente.setWidget(0, 0, imgTec);
	    cellUtFormatter.setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_BOTTOM);
	    cellUtFormatter.setRowSpan(0, 0, 2);
	    
	    // Info utente
	    Label labelNome = new Label();
	    labelNome.setStyleName("label");
	    labelNome.setText("Utente: " + tecnico.getNome());
	    flexUtente.setWidget(0, 1, labelNome);
	    
	    Label labelProfilo = new Label();
	    labelProfilo.setStyleName("label");
	    labelProfilo.setText("Profilo: " + tecnico.getIdUtente());
	    flexUtente.setWidget(1, 0, labelProfilo);
	    
	    flexTable.setWidget(0, 1, flexUtente);
	    add(flexTable);
	}
}
